package com.lkd.web.controller;


import com.lkd.entity.Goods;
import com.lkd.mapper.GoodsMapper;
import com.lkd.mapper.GoodsOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
//@RestController  // @Controller + @ResponseBody
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/sayHello")
    @ResponseBody
    public Map sayHello(){
        List list = Arrays.asList(1,2,3,4,5,6,7);
        Map map =new HashMap<String,Object>();
        map.put("a","111");
        map.put("b","222");
        System.out.println("======我进来了======");
        return map;
    }

    @RequestMapping("/sayHi")
    @ResponseBody
    public String sayHi(){
        System.out.println("I am coming...");
        return "你好";
    }


    @RequestMapping("/testView")
    public String testView(){
        return "redirect:/login.html";
    }
    //http://localhost:8080/test/testView

    @Autowired
    private GoodsMapper goodsMapper;

    @GetMapping("/testMybatisCascade")
    public @ResponseBody Goods testMybatisCascade(Long goodsId){
        return goodsMapper.selectByPrimaryKey(goodsId);
        //http://localhost:8080/test/testMybatisCascade?goodsId=1
    }

    @Autowired
    private GoodsOrderMapper goodsOrderMapper;
    /*
     * 测试：ont to many
     * TODO: 查询订单信息并级联查询出相应的明细信息
     */

    @GetMapping("/testMybatisCascade2")
    public @ResponseBody Object testMybatisCascade2(Integer orderId){
        return goodsOrderMapper.selectOrderAndOrderDetail(orderId);
        //http://localhost:8080/test/testMybatisCascade2?orderId=1
    }


    @RequestMapping("/testJson")
    @ResponseBody
    public Object testJson(Integer a){
        System.out.println(a);
        return a;
    }

}
